package com.aboverock.core.shiro.util;

import org.apache.commons.lang3.StringUtils;

/**
 * Shiro权限控制-restful url工具类.
 *
 * @author Rock Wang
 */
public class ShiroRestUrlUtil {

    public static String buildRestUrl(String httpMethod, String rawUrl) {
        if (StringUtils.isBlank(httpMethod)) {
            return rawUrl;
        }

        return new StringBuilder().append("[").append(httpMethod.toUpperCase()).append("]")
                .append(rawUrl).toString();
    }

    public static boolean isRestUrl(String url) {
        return url.startsWith("[");
    }

    public static String getRawUrl(String url) {
        return isRestUrl(url) ? StringUtils.substringAfter(url, "]") : url;
    }
}
